<template>
  <el-dialog
    class="base-dialog readonly"
    :custom-class="'panna-dialog_medium'"
    title="选择委托单"
    :visible.sync="dialogVisible"
    :append-to-body="true"
    :before-close="handleClose"
  >
    <p slot="title">选择委托单</p>
    <div>
      <el-form ref="filterForm" :model="filterForm" inline>
        <el-form-item label="委托单号" prop="orderNum">
          <el-input
            v-model="filterForm.orderNum"
            placeholder="委托单号"
            clearable
          />
        </el-form-item>
        <el-form-item class="base-filter-button">
          <el-button type="primary" @click="init">查询</el-button>
          <el-button @click="cancelForm">清空</el-button>
        </el-form-item>
      </el-form>

      <el-table
        ref="table"
        border
        :data="tableData"
        style="width: 100%"
        height="300px"
      >
        <el-table-column prop="orderNum" label="委托单号" width="150px">
          <template slot-scope="scope">
            <a style="color: blue" @click="clickOrderNum(scope.row)">
              {{ scope.row.orderNum }}
            </a>
          </template>
        </el-table-column>
        <el-table-column prop="customerName" label="委托单位" />
        <el-table-column prop="customerAddress" label="委托单位地址" />
        <el-table-column prop="entrustPeople" label="委托人" />
        <el-table-column prop="phone" label="电话" />
        <el-table-column prop="email" label="邮箱" />
      </el-table>
      <!-- 分页 -->
      <BasePagination
        :total="pageInfo.total"
        :current-page="pageInfo.pageIndex"
        @changePage="changePage"
        @sizeChange="sizeChange"
      />
      <!-- 选择委托样品检测 -->
      <!-- <ChioceEntrustSampleDetection
        ref="ChioceEntrustSampleDetection"
        :dialog-form-visible.sync="dialogFormVisibleEntrustSampleDetection"
        :entrust-id.sync="entrustId"
        @closeChioseEntrustSampleDetection="closeChioseEntrustSampleDetection"
      /> -->
    </div>
  </el-dialog>
</template>

<script>
import { getEntrustOrderList } from "../../../api/EntrustManage/EntrustOrder.js";
// import ChioceEntrustSampleDetection from "./ChioceEntrustSampleDetection.vue";
export default {
  name: "ChioceEntrustOrderMessage",
  // components: { ChioceEntrustSampleDetection },
  props: {
    dialogFormVisible: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      entrustData: {},
      entrustId: "",
      dialogFormVisibleEntrustSampleDetection: false,
      isShowDialog: false,
      dialogVisible: false,
      tableData: [],
      filterForm: {
        customerName: "",
        orderStatusCode: -1,
        orderNum: "",
        entrustOrderState: 1,
      },
      pageInfo: {
        pageIndex: 1,
        pageSize: 10,
        total: 0,
      },
    };
  },
  watch: {
    dialogFormVisible(val) {
      this.dialogVisible = val;
      this.init();
    },
    dialogVisible(val) {
      this.$emit("update:dialogFormVisible", val);
    },
  },
  methods: {
    // 清空筛选条件
    cancelForm() {
      this.$refs.filterForm.resetFields();
      this.init();
    },
    closeChioseEntrustSampleDetection(data) {
      this.$emit("closeChioseEntrustOrder", data);
      this.handleClose();
    },
    // 点击委托单号
    clickOrderNum(row) {
      this.entrustData = row;
      this.entrustId = row.id;
      // this.dialogFormVisibleEntrustSampleDetection = true;
      this.closeChioseEntrustSampleDetection();
    },
    // 初始化
    async init() {
      getEntrustOrderList({ ...this.filterForm, ...this.pageInfo }).then(
        (res) => {
          this.tableData = res.data.dataList ? res.data.dataList : [];
          this.pageInfo.total = res.data.total;
        }
      );
    },
    sizeChange(val) {
      this.pageInfo.pageIndex = 1;
      this.pageInfo.pageSize = val;
      this.init();
    },
    // 切换页码
    changePage(page) {
      this.pageInfo.pageIndex = page;
      this.init();
    },
    // 关闭弹框
    handleClose() {
      this.dialogVisible = false;
    },
  },
};
</script>

